At 3-5 weeks' gestation, the gonadal ridge or indifferent gonad develops, and, at 6 weeks' gestation, primordial germ cell migration occurs.
Soon after, Sertoli cells develop and secrete müllerian-inhibiting substance (MIS), the level of which remains high throughout gestation and causes regression of müllerian ducts.
At 9 weeks' gestation, Leydig cells develop and secrete testosterone.
++++++++++++++++++++++
Sexual differentiation genes are located on the Y chromosome, the primary of which is the SRY gene, also called the testis-determining factor.
The SRY gene is found on the short arm of the Y chromosome and influences Sertoli cell differentiation, mesonephric ridge cell development, and male architectural development of the gonad, including blood vessels and other structures of the testes. Several other genes, including those that express steroidogenic factor-1, WT1, and DAX1, on other chromosomes, are also necessary for normal testicular development.
To date, multiple mutations of the SRY gene have been reported and all are associated with sex reversals (female phenotype).

Genetics and biology of early reproductive tract development1
Genes in other locations are also important for complete male sexual differentiation. DAX1, a nuclear hormone receptor, can alter SRY activity during development by suppressing genes downstream to SRY that would normally induce testicular differentiation. A second gene, WNT4, largely confined to the adult ovary, may also serve as an “antitestis” gene. In very rare male individuals, a Y chromosome may be absent, but the SRY gene may be present on another chromosome, most commonly the X chromosome, resulting in a male phenotype. It is becoming apparent that genes such as WNT4 and NR0B1 can proactively induce female gonadal development even in the presence of SRY, thereby further complicating the picture. This may account for individuals who are exceptions to the normal sexual dichotomy (eg, males with a uterus or females with an XY karyotype) or who exhibit biologic and/or behavioral characteristics of both sexes.1
Male gonadal development precedes female development, and the early secretion of testosterone and antimüllerian hormone (AMH) steers the further development of the genital tracts away from the default female phenotype. At a critical point, AMH, produced by Sertoli cells, and testosterone, secreted by Leydig cells, must be produced in sufficient amounts. AMH acts locally, suppressing the Müllerian duct system. Testosterone acts systemically, causing the differentiation of the mesonephric duct system and male phenotype of the urogenital tubercle, urogenital sinus, and urogenital folds. Enzymes involved in testosterone biosynthesis and conversion to dihydrotestosterones are regulated by genes located on autosomes. The ability to secrete AMH is a recessive trait coded on either an autosome or the X chromosome, and genes for the development of cytoplasmic receptors of androgens seem to be coded on the X chromosome.1
Prenatal ultrasonography shows no testicular descent before 28 weeks' gestation, other than transabdominal movement to the internal inguinal ring. Transinguinal migration, thought to be under hormonal control, occurs at 28-40 weeks' gestation, usually resulting in a scrotal testis by the end of a full term of gestation.
1. Book Chapter, Sexual Differentiation, Roger P. Smith M, Netter's Obstetrics and Gynecology, 1, 3-4